import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '赛事id',
    align: 'center',
    dataIndex: 'saisId_dictText',
  },
  {
    title: '赛事进程id',
    align: 'center',
    dataIndex: 'saisjcId_dictText',
  },
  {
    title: '区域id',
    align: 'center',
    dataIndex: 'quyId',
    customRender: ({ text }) => {
      return render.renderCategoryTree(text, 'C05');
    },
  },
  {
    title: '赛事区域code',
    align: 'center',
    dataIndex: 'saisqyCode',
  },
  {
    title: '评审组id',
    align: 'center',
    dataIndex: 'pingszId_dictText',
  },
  {
    title: '起始时间',
    align: 'center',
    dataIndex: 'qissj',
    customRender: ({ text }) => {
      return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
    },
  },
  {
    title: '截止时间',
    align: 'center',
    dataIndex: 'jiezsj',
    customRender: ({ text }) => {
      return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
    },
  },
  {
    title: '是否已生成任务',
    align: 'center',
    dataIndex: 'shifyscrw_dictText',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '赛事id',
    field: 'saisId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'cdba2_sais,mingc,id',
    },
    //colProps: {span: 6},
  },
  {
    label: '赛事进程id',
    field: 'saisjcId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'cdba2_saisjc,jincmc,id',
    },
    //colProps: {span: 6},
  },
  {
    label: '区域id',
    field: 'quyId',
    component: 'JCategorySelect',
    componentProps: {
      pcode: 'C05', //back和事件未添加，暂时有问题
    },
    //colProps: {span: 6},
  },
  {
    label: '评审组id',
    field: 'pingszId',
    component: 'JSearchSelect',
    componentProps: {
      dict: 'pingsz',
    },
    //colProps: {span: 6},
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '赛事id',
    field: 'saisId',
    component: 'JDictSelectTag',
    componentProps: ({ formActionType, formModel }) => {
      return {
        dictCode: 'cdba2_sais,mingc,id',
        onChange: (value) => {
          console.log('saisId: ' + value);

          const { updateSchema } = formActionType;
          updateSchema([
            {
              field: 'saisjcId',
              componentProps: { dictCode: 'cdba2_saisjc,jincmc,id,sais_id = ' + value },
            },
          ]);
        },
      };
    },
  },
  {
    label: '赛事进程id',
    field: 'saisjcId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'cdba2_saisjc,jincmc,id',
    },
  },
  {
    label: '区域id',
    field: 'quyId',
    component: 'JCategorySelect',
    componentProps: {
      pcode: 'C05', //TODO back和事件未添加，暂时有问题
    },
  },
  {
    label: '赛事区域code',
    field: 'saisqyCode',
    component: 'Input',
  },
  {
    label: '评审组id',
    field: 'pingszId',
    component: 'JSearchSelect',
    componentProps: {
      dict: 'pingsz',
    },
  },
  {
    label: '起始时间',
    field: 'qissj',
    component: 'DatePicker',
  },
  {
    label: '截止时间',
    field: 'jiezsj',
    component: 'DatePicker',
  },
  {
    label: '是否已生成任务',
    field: 'shifyscrw',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'yn',
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  saisId: { title: '赛事id', order: 0, view: 'list', type: 'string', dictTable: 'cdba2_sais', dictCode: 'id', dictText: 'mingc' },
  saisjcId: { title: '赛事进程id', order: 1, view: 'list', type: 'string', dictTable: 'cdba2_saisjc', dictCode: 'id', dictText: 'jincmc' },
  quyId: { title: '区域id', order: 2, view: 'cat_tree', type: 'string', pcode: 'C05' },
  saisqyCode: { title: '赛事区域code', order: 3, view: 'text', type: 'string' },
  pingszId: { title: '评审组id', order: 4, view: 'sel_search', type: 'string', dictCode: 'pingsz' },
  qissj: { title: '起始时间', order: 5, view: 'date', type: 'string' },
  jiezsj: { title: '截止时间', order: 6, view: 'date', type: 'string' },
  shifyscrw: { title: '是否已生成任务', order: 7, view: 'list', type: 'string', dictCode: 'yn' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
